package com.hs.server.runnable;

import com.hs.server.config.MyConfig;
import com.hs.server.service.VehQueuexxbService;
import com.hs.server.service.WebApiService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Description 隔5s查询一次数据库，保证数据库作业表作业数量大于5
 * @Author: chenjiarui
 * @Date: 2021-07-16 10:50
 */
@Data
@Component
@Slf4j
public class WorkSearcher implements Runnable {
    VehQueuexxbService vehQueuexxbService;
    WebApiService webApiService;
    @Autowired
    private MyConfig myConfig;

    public WorkSearcher(VehQueuexxbService vehQueuexxbService, WebApiService webApiService) {
        this.vehQueuexxbService = vehQueuexxbService;
        this.webApiService = webApiService;
    }

    @Override
    public void run() {
        while (myConfig.openThread) {
            try {
                if (vehQueuexxbService.getTaskNum() < 50)
                    webApiService.GetXbjcxtZp();
                Thread.sleep(myConfig.timeInterval);
            } catch (Exception e) {
                log.error("WorkSearcher error：", e);
            }

        }
    }
}
